package com.moorror.codegenvel.view.window.history;

import com.intellij.openapi.project.Project;
import com.moorror.codegenvel.common.tree.MTTreeCell;
import com.moorror.codegenvel.view.component.AbstractCodeGenByVelocitySetTab;
import com.moorror.codegenvel.view.component.AbstractLRTabContent;
import com.moorror.codegenvel.view.component.CodeGenByVelocityComponent;
import com.moorror.codegenvel.view.component.TabContentRightShow;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;

/**
 * @Author jiyanghuang
 * @Date 2024/4/11 23:13
 */
public class HistoryDataTabContent extends AbstractLRTabContent<HistoryLeft, TabContentRightShow> {

    public HistoryDataTabContent(Project project, AbstractCodeGenByVelocitySetTab abstractToolSetTab, String tabId, String type) {
        super(project, new HistoryLeft(project, abstractToolSetTab, type), new TabContentRightShow(project, false), abstractToolSetTab, tabId);
        r.fillLeft(l);
        TabContentRightShow tabContentRightShow = CodeGenByVelocityComponent.getInstance(project).findInstance(TabContentRightShow.class, abstractToolSetTab.tabName(), tabId);
        if (null != tabContentRightShow && null == tabContentRightShow.getCurrentShow()) {
            tabContentRightShow.updatePanel(new JPanel(new BorderLayout()));
        }
    }

    public MTTreeCell currentSelect(){
        JTree jTree = this.l.jTree();
        if(null == jTree){
            return null;
        }
        if(null == jTree.getSelectionPath() || null == jTree.getSelectionPath().getLastPathComponent()){
            return null;
        }
        DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode)jTree.getSelectionPath().getLastPathComponent();
        if(null == selectNode){
            return null;
        }
        return (MTTreeCell)selectNode.getUserObject();
    }
}
